extends Node
class_name Printer

# 配置API地址
const API_URL = "http://127.0.0.1:8082/print"

func print_certificate(data: Dictionary):
	var http_request = HTTPRequest.new()
	add_child(http_request)
	http_request.request_completed.connect(_on_request_completed)
	
	# 准备请求数据
	var headers = ["Content-Type: application/json"]
	var json_data = JSON.stringify(data)
	
	# 发送异步请求
	var error = http_request.request(API_URL, headers, HTTPClient.METHOD_POST, json_data)
	if error != OK:
		push_error("HTTP请求失败: " + str(error))

func _on_request_completed(result, response_code, headers, body):
	# 移除请求节点
	var http_request = get_node_or_null("HTTPRequest")
	if http_request:
		http_request.queue_free()
	
	var response = JSON.parse_string(body.get_string_from_utf8())
	print(response)
